package be.redo.model.entities;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * @author Frank Plain old Java class to represent a database table row.
 *         Represents a AirlineCompany in the domain model.
 * 
 */
@Entity
@NamedQueries({
		@NamedQuery(name = "findAllAirlineCompanies", query = "select a from AirlineCompany a order by a.name"),
		@NamedQuery(name = "findAirlineCompaniesByNameLike", query = "select a from AirlineCompany a where a.name like( :name )"),
		@NamedQuery(name = "findAantalAirlineCompanies", query = "select count(a) from AirlineCompany a") })
public class AirlineCompany implements Serializable {

	/**
	 * Generated serialVersionUID.
	 */
	private static final long serialVersionUID = -1266911441297752217L;

	/**
	 * Name of the airlinecompany.
	 */
	@NotNull
	@Size(min = 1, max = 255)
	private String name;

	/**
	 * Two character IATA code of the airlinecompany A-Z of 0-9.
	 */
	@NotNull
	@Pattern(regexp = "[A-Z0-9]{2}")
	@Column(name = "code")
	private String iataCode;

	/**
	 * @return the airlineCode
	 */
	public String getIataCode() {
		return iataCode;
	}

	/**
	 * @param airlineCode
	 *            the airlineCode to set
	 */
	public void setIataCode(String airlineCode) {
		this.iataCode = airlineCode;
	}

	@Override
	public String toString() {
		return ReflectionToStringBuilder.toString(this,
				ToStringStyle.SHORT_PREFIX_STYLE);
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Generated key by the Database
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "airline_company_id")
	private Long airlineCompanyId;

	public Long getAirlineCompanyId() {
		return this.airlineCompanyId;
	}

	public void setAirlineCompanyId(Long id) {
		this.airlineCompanyId = id;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((iataCode == null) ? 0 : iataCode.hashCode());
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		AirlineCompany other = (AirlineCompany) obj;
		if (iataCode == null) {
			if (other.iataCode != null) {
				return false;
			}
		} else if (!iataCode.equals(other.iataCode)) {
			return false;
		}
		return true;
	}

}
